package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.CourseTeacherDto;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(value = "教资管理", tags = "教资管理")
public class CourseTeacherController {

    @Autowired
    private CourseTeacherService courseTeacherService;


    @ApiOperation("查询教师")
    @ApiImplicitParam(value = "courseId", required = true, dataType = "Long", paramType = "Path")
    @GetMapping("/courseTeacher/list/{courseId}")
    public List<CourseTeacher> ListTeacherInfo(@PathVariable("courseId") Long courseId) {
        log.info("课程id为：{}", courseId);
        return courseTeacherService.getListTeacherByCourseId(courseId);
    }

    @ApiOperation("添加教师信息")
    @PostMapping("/courseTeacher")
    public CourseTeacher addCourseTeacher(@RequestBody CourseTeacherDto courseTeacherDto) {
        log.info("添加教师基本信息：{}", courseTeacherDto);
        Long companyid=1232141425L;
        return courseTeacherService.addCourseOrSaveTeacher(courseTeacherDto,companyid);
    }

    @ApiOperation("修改教师信息")
    @PutMapping("/courseTeacher")
    public CourseTeacher modifyCourseTeacher(@RequestBody CourseTeacherDto courseTeacherDto) {
        log.info("修改教师基本信息：{}", courseTeacherDto);
        Long companyid=1232141425L;
        return courseTeacherService.addCourseOrSaveTeacher(courseTeacherDto,companyid);
    }

    @ApiOperation("删除教师信息")
    @ApiImplicitParams({@ApiImplicitParam(value = "课程id",required = true,dataType = "Long",paramType = "Path"),
    @ApiImplicitParam(value = "教师id",required = true,dataType = "Long",paramType = "Path")})
    @DeleteMapping("/courseTeacher/course/{courseId}/{courseTeacherId}")
    public void deleteCourseTeacher(@PathVariable("courseId") Long courseId,@PathVariable("courseTeacherId") Long courseTeacherId){
        log.info("课程id:{},教师id:{}",courseId,courseTeacherId);
        Long companyid=1232141425L;
        courseTeacherService.deleteCourseTeacher(courseId,courseTeacherId,companyid);
    }

}
